package cn.service.marketingService.MarketingServiceImpl;

import cn.service.marketingService.BrandMarketingService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.*;
import entity.marketingEntity.BrandMarketingCondition;
import entity.marketingEntity.Brandmarketing;
import mapper.marketingMapper.BrandmarketingMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 朱颢阳
 * @description
 * @time 2024/8/29 16:44
 */
@Service
public class BrandMarketingServiceImpl implements BrandMarketingService {
    @Resource
    BrandmarketingMapper mapper;

    @Override
    public Result getBrandMarking(BrandMarketingCondition condition) {
        PageHelper.startPage(condition.getCurrentPage(),condition.getPageSize());
        Page<Brandmarketing> page= (Page<Brandmarketing>) mapper.selectAll(condition);
        System.out.println(page.getTotal());
        return Result.success((int)page.getTotal(),page.getResult());
    }

    @Override
    public Result updateBrandMarkingRecommend(Integer id, Integer recommend) {
        if (mapper.updateBrandMarkingRecommend(id,recommend)>0){
            return Result.success("推荐状态更新成功");
        }else{
            return Result.failed(500,"推荐状态更新失败！");
        }
    }

    @Override
    public Result updateBrandMarkingSort(Integer id, Integer sort) {
        if (mapper.updateBrandMarkingSort(id,sort)>0){
            return Result.success("排序更新成功");
        }else{
            return Result.failed(500,"排序更新失败！");
        }
    }

    @Override
    public Result addBrandMarketing(List<String> list) {
        for (String s : list) {
            if(mapper.insert(new Brandmarketing(s))<1){
                return Result.failed(500,"品牌推荐失败！");
            }
        }
        return Result.success("品牌推荐成功");
    }

    @Override
    public Result deleteBrandMarketing(Integer id) {
        if (mapper.deleteByPrimaryKey(id)>0){
            return Result.success("删除成功");
        }else{
            return Result.failed(500,"删除失败！");
        }
    }
}
